package com.working.libcommon.exts

import com.working.libcommon.BuildConfig


inline fun <reified R> Any.cast(): R? {
    return this as? R
}

inline fun runOnDebug(block: () -> Unit) {
    if (BuildConfig.DEBUG) {
        block()
    }
}
val Any?.isNotNull
    get() = this != null

val Any?.isNull
    get() = this == null

inline fun <T, R> T.doWithTry(block: (T) -> R): R? {
    return try {
        block(this)
    } catch (e: Throwable) {
        e.printStackTrace()
        null
    }
}

fun <T> MutableList<T>.swap(i: Int, j: Int) {
    set(i, set(j, this[i]))
}